package com.zmn.oms.dubbo.impl.conf.distribute;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.oms.business.interfaces.conf.distribute.DistributeWeightListBService;
import com.zmn.oms.common.dio.conf.distribute.DistributeWeightDIO;
import com.zmn.oms.common.dro.conf.distribute.DistributeArgsDRO;
import com.zmn.oms.common.dro.conf.distribute.DistributeConfigDRO;
import com.zmn.oms.dubbo.interfaces.conf.distribute.DistributeWeightListRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.conf.distribute.DistributeWeightQuery;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.Objects;

/**
 * 类描述：派单参数查询远程查询接口实现
 *
 * @author liuying
 * @date 2022/02/24 18:16
 */
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 5000, retries = -1, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class DistributeWeightListRemoteServiceImpl implements DistributeWeightListRemoteService {

    @Resource
    private DistributeWeightListBService distributeWeightListBService;

    @Override
    @ReadOnlyConnection
    public ResponseDTO<DistributeArgsDRO> findDistributeArgsById(@NotNull(message = "平台ID不能为空") Integer plat, @NotNull(message = "公司ID不能为空") Integer companyId,
                                                                 @NotNull(message = "城市ID不能为空") Integer cityId, @NotNull(message = "业务类型不能为空") Integer bizType) {
        DistributeArgsDRO dro = distributeWeightListBService.findDistributeArgsById(plat, companyId, cityId, bizType);
        if (Objects.isNull(dro)) {
            log.debug("#DistributeWeightListBServiceImpl#findDistributeArgsById#未查询到派单参数信息。plat:{}, companyId:{}, cityId:{}", plat, companyId, cityId);
            return ResponseDTO.success(null, "暂无配置信息");
        }
        return ResponseDTO.success(dro, GlobalConsts.SUCCESS_MSG);
    }

    @Override
    public ResponseDTO<DistributeConfigDRO> findDistributeConfig(DistributeWeightDIO distributeWeightDIO) {
        DistributeWeightQuery distributeWeightQuery = DistributeWeightQuery.builder()
                .plat(distributeWeightDIO.getPlat())
                .companyId(distributeWeightDIO.getCompanyId())
                .cityId(distributeWeightDIO.getCityId())
                .bizType(distributeWeightDIO.getBizType())
                .productGroupId(distributeWeightDIO.getProductGroupId()).build();
        return ResponseDTO.success(distributeWeightListBService.findDistributeConfig(distributeWeightQuery));
    }
}
